home *** CD-ROM | disk | FTP | other *** search
/ Shareware Grab Bag / Shareware Grab Bag.iso / 007 / bascom2.lqr / PATCHER2.BAS < prev   
Encoding:
BASIC Source File  |  1986-02-21  |  2.5 KB  |  62 lines

  1. 10 'PATCHER - file patching program - PROGRAMMERS JOURNAL Vol 1, No 6, Pg. 21
  2. 20 'Copyright 1983 - Data Base Decisions, Atlanta, GA
  3. 30 'This program is used to patch other programs or files. It requires
  4. 40 'a data file containing the patches. The first three items in the
  5. 50 'patch file are the name of the file to be patched, a check sum, and
  6. 60 'comments. For each byte to be patched, there is one record containing
  7. 70 'the offset of the byte to be patched, the old value of the byte,
  8. 80 'and the new (patch) value.
  9. 90 'Patches are generated using program  GENPATCH.BAS
  10. 100 'Note: If the offset is greater than 32,767, BASIC 2.00 must be used.
  11. 110 CLS
  12. 120 DEFINT A-Z
  13. 130 CLEAR
  14. 140 ON ERROR GOTO 500
  15. 145 ON ERROR GOTO 0
  16. 150 CLOSE
  17. 160 PRINT : INPUT "Name of file containing patches";PAT$
  18. 165 PRINT :PRINT "Path (drive and/or subdirectory) to file to be patched"
  19. 166 INPUT "(Hit <enter> if on same drive and same directory)";PATH$
  20. 168 IF PATH$=CHR$(13) THEN PATH$=""
  21. 169 IF INSTR(PATH$,"\")<>0 AND RIGHT$(PATH$,1)<>"\" THEN PATH$=PATH$+"\"
  22. 170 IF PAT$="" THEN  END
  23. 180 OPEN "i",#1,PAT$
  24. 190 INPUT #1,FIL$,CKSUM!,COMMENT$
  25. 195 FIL$=PATH$+FIL$
  26. 200 OPEN "i",#2,FIL$    'is it there
  27. 210 PRINT "Patching: " FIL$
  28. 220 PRINT "Comments: " COMMENT$
  29. 230 CLOSE 2
  30. 240 OPEN "r",#2,FIL$,1  'reopen as random file
  31. 250 FIELD 2,1 AS R$
  32. 260 FILE.LEN = LOF(2)
  33. 270 IF EOF(1) THEN 450
  34. 280 INPUT# 1,BYTE!,OLDVAL,NEWVAL    'get patch
  35. 290 NEWSUM!=(NEWSUM!+BYTE!+OLDVAL!+NEWVAL!)
  36. 300 PRINT BYTE!,OLDVAL,NEWVAL, "Checksum " NEWSUM!
  37. 310 IF NEWSUM! > 32767 THEN NEWSUM!=NEWSUM!-32767: GOTO 310
  38. 320 IF BYTE! > FILE.LEN THEN PRINT "Byte " BYTE! " is beyond end of file": GOTO 400
  39. 330 GET 2,BYTE!
  40. 340 R=ASC(R$)
  41. 350 IF R <> OLDVAL THEN PRINT "Old value for byte " BYTE! " is " R " not " OLDVAL: GOTO 400
  42. 360 LSET R$=CHR$(NEWVAL)
  43. 370 PUT 2,BYTE!
  44. 380 APPLIED=APPLIED+1
  45. 390 GOTO 270
  46. 400 REM *** invalid condition ***
  47. 410 BEEP:INPUT "Continue (y/n)";ANS$
  48. 420 IF ANS$="Y" OR ANS$="y" THEN 390
  49. 430 IF ANS$="N" OR ANS$="n" THEN 450
  50. 440 GOTO 400
  51. 450 REM *** wrap it up ***
  52. 460 IF CKSUM!=NEWSUM! THEN PRINT "Checksums match" ELSE PRINT "Checksums do not match -- input value is"CKSUM! " and calculated value is "NEWSUM!: BEEP
  53. 470 PRINT "Patches applied: " APPLIED
  54. 480 CLOSE
  55. 490 END
  56. 500 REM *** error handler ***
  57. 510 UNABLE$="Unable to "
  58. 520 IF ERL=180 OR ERL=280 THEN PRINT UNABLE$ "read " PAT$
  59. 530 IF ERL=200 OR ERL=240 OR ERL=330 THEN PRINT UNABLE$ "read " FIL$
  60. 540 IF ERL=370 THEN PRINT UNABLE$ "write " FIL$
  61. 550 RESUME 120
  62.